package cruciverba.file;

import java.io.FileWriter;
import java.io.IOException;
import java.util.Observable;
import java.util.Observer;

import javax.swing.JTextField;

import cruciverba.model.Verifica;

public class CruciverbaFileWriter implements Observer {

	private Verifica verifica;
	private JTextField field;
	private FileWriter writer;

	public CruciverbaFileWriter(Verifica verifica,
		 JTextField field, FileWriter writer) {
		super();
		this.verifica = verifica;
		this.field = field;
		this.writer = writer;
		verifica.addObserver(this);
	
		
	}

	@Override
	public void update(Observable o, Object arg) {

		try {
			writer = new FileWriter("Log.txt", true);
			writer.write(verifica.getTipo_verifica() +"\t"+ field.getText() +"\t"
					+ verifica.getResultVerifica() + "\n");
			writer.close();
					
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
